const express = require("express");
const bodyParser = require("body-parser");
const cors = require("cors");

const Utils = require("./src/utils");
const Send = require("./src/utils/Send");
const config = Utils.getConfig();

const app = express();

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));

// 设置跨域访问
app.use(
  cors({
    credentials: true,
    origin: config.origin,
  })
);

app.use("/", require("./src/main.js"));

// 后置错误处理中间件
app.use((err, req, res, next) => {
  res.send(Send.fail(err));
});

app.listen(config.port, () => {
  console.log(`service success start,port is ${config.port}`);
});
